#include "page.h"
#include "keyword.h"
#include "assert.h"
#include "log.h"

keyword_t* create_keyword(url_t* url)
{
	assert(url != NULL);
	keyword_t* k = new keyword_t;
	k->url = create_url(url);
	return k;
}

keyword_t* transfer_keyword_from_page(page_t* page)
{
	keyword_t* k = page->keyword;
	page->keyword = NULL;//import!!!, page will not have keywords
	return k;
}
int release_keyword(void* data)
{
	keyword_t* keyword = (keyword_t*)data;
	if(keyword == 0)
		return 0;
		
	release_url(keyword->url);
	keyword->keywords.clear();	
	return 0;
}
int add_keyword(keyword_t* keyword, const string& word, int count)
{
	assert(keyword != 0);
	keyword->keywords[word] += count;
	logger("word:%s\tcount:%d\n", word.c_str(), keyword->keywords[word]);	
	return 0;	
}

void print_keyword(keyword_t* keyword)
{
	logger("print_keyword\n");
	map<string, int>::iterator it = keyword->keywords.begin();
	for(; it != keyword->keywords.end(); it++)
	{
		logger("word:%s(%d)\n", (*it).first.c_str(), (*it).second);
	}
}
